import re
import requests


def load_bytes_test() -> str:
    with open('./b.txt', 'r') as f:
        return f.readline()


def tin_url_list(url_list: list) -> (list, int, int):
    temp = []
    # first = 0
    pattern4findfirst = r'/\d+'

    for li in url_list:
        if li not in temp:
            temp.append(li)
    t = re.findall(pattern4findfirst, url_list[0])
    first = int(t[0][1:])
    # print(url_list[0].split(str(first)))

    return temp, first, len(temp)


def get_pic(url_list: list, first: int):
    for url in url_list:
        with open('./tout/' + str(first) + '.png', 'wb+') as f:
            nama_data = requests.get(url)
            f.write(nama_data.content)
            print(str(first) + 'ready')
        first += 1


def check_and_mkdir() -> str:
    return './tout/'


if __name__ == '__main__':
    patten = r'https://stickershop.line-scdn.net/stickershop/v1/sticker/\d+/android/sticker.png'
    #
    res = re.findall(patten, load_bytes_test())

    url_list, first, length = tin_url_list(res)
    get_pic(url_list, first)

    # print(load_bytes_test())
